package cn.devices.service.impl;

import cn.devices.entity.TbDevice;
import cn.devices.mapper.TbDeviceMapper;
import cn.devices.service.TbDeviceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;

/**
 * <p>
 * 设备表 服务实现类
 * </p>
 *
 * @author 秋水浮萍
 * @since 2021-02-07
 */
@Service
public class TbDeviceServiceImpl implements TbDeviceService {


    @Autowired
    private TbDeviceMapper mapper;

    @Override
    public int devicesAdd(TbDevice device) {
        return mapper.devicesAdd(device);
    }

    @Override
    public int devicesUpdate(TbDevice device) {
        return mapper.devicesUpdate(device);
    }

    @Override
    public int deviceCodeUpdate(String deviceCodeOld, String deviceCodeNew) {
        return mapper.deviceCodeUpdate(deviceCodeOld, deviceCodeNew);
    }

    @Override
    public int deviceDeleteFalse(String deviceCode) {
        return mapper.deviceDeleteFalse(deviceCode);
    }

    @Override
    public PageInfo<TbDevice> tbDeviceList(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        List<TbDevice> list = mapper.tbDeviceList();
        for (TbDevice item : list) {

            if ("1".equals(item.getDeviceStatus())){
                item.setDeviceStatus("设备正常");
            }else {
                item.setDeviceStatus("设备故障");
            }
            if ("0".equals(item.getIsBorrow())){
                item.setIsBorrow("在库");
            }else {
                item.setIsBorrow("借出");
            }

        }
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<TbDevice> level3(int pageIndex,int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        List<TbDevice> list = mapper.level3();
        return new PageInfo<>(list);
    }

    @Override
    public TbDevice tbDevice(String deviceCode) {
        return mapper.tbDeviceByCode(deviceCode);
    }

    @Override
    public String deviceStatus(String deviceCode) {
        return mapper.deviceStatus(deviceCode);
    }

    @Override
    public List<TbDevice> getNotRegister() {
        return mapper.getNotRegister();
    }

    @Override
    public String maxDeviceCode() {
        return mapper.maxDeviceCode();
    }

    @Override
    public List<TbDevice> getRegister() {
        return mapper.getRegister();
    }

    @Override
    public TbDevice getByCode(String deviceCode) {
        return mapper.getByCode(deviceCode);
    }
}
